#pragma once

#include "vectormath.h"

namespace Tmpl {

#define MAX_TEXTURE_COUNT 32

struct Vertex
{
public:
	Vertex(){}
	Vertex(Vec3f aPos, Vec2f aUV):pos(aPos), uv(aUV){}
	void NormalizeTexValues();

	Vec3f pos;
	Vec3f normal;
	Vec2f uv;
	float texValues[MAX_TEXTURE_COUNT];
};

class WorldMap;
class Image;
class ShaderProgram;
class Sphere
{
public:
	Sphere(int size, float tiling);

	int AddTexture(const char* filename);

	void Update(WorldMap* map, Vec3f playerPos);
	void Render(Matrix4x4f projection, Matrix4x4f modelView);

	int GetTriangleCount(){return mSize * mSize * 2;}
	int GetSize(){return mSize;}
private:
	void UpdateVBO();
	void BindVBO(ShaderProgram* shader);
	void UnbindVBO(ShaderProgram* shader);

	void RenderFlat(Matrix4x4f projection, Matrix4x4f modelView);
	void RenderTextured(Matrix4x4f projection, Matrix4x4f modelView);

	Vertex* mVertices;
	int mSize;

	ShaderProgram* mShader;
	ShaderProgram* mShaderFlat;
	unsigned int mVBO;
	unsigned int mVBOIndices;

	Image* mTextures[MAX_TEXTURE_COUNT];
	int mTextureCount;
};

}; // namespace Tmpl